//
//  BNDOfficeDocModel.m
//  OfficeDoc
//
//  Created by pie on 2022/4/1.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDOfficeDocModel.h"
#import "NSString+Helper.h"
#import "BNDPreference.h"

@implementation BNDOfficeDocModel

+ (NSDictionary *)modelCustomPropertyMapper
{
    return @{@"modelID" : @"id"
             };
}

- (void)setAttachment:(NSString *)attachment
{
    _attachment = attachment;

    _attachmentArray = [BNDOfficeDocModel toArrayOrNSDictionary:attachment];
    if(![_attachmentArray isKindOfClass:NSArray.class]){
        _attachmentArray = [NSArray array];
    }
}

+ (id)toArrayOrNSDictionary:(NSString *)jsonData
{
    if (jsonData != nil) {
        NSData* data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
        id jsonObject = [NSJSONSerialization JSONObjectWithData:data
                                                        options:NSJSONReadingAllowFragments
                                                          error:nil];
 
        if (jsonObject != nil){
            return jsonObject;
        }else{
            // 解析错误
            return nil;
        }
    }
    return nil;
}

- (void)setSignaturePic:(NSString *)signaturePic
{
    _signaturePic = [[BNDPreference sharedInstance] handleProduceImageUrl:signaturePic];
}

- (void)setContent:(NSString *)content
{
    _content = content;
    if(content.length ==0){
        _content = @"";
    }
    _listContent = [NSString handleOfficeDocContent:_content];
    
}
@end
